#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int cuttingRopeDp(const int &length) {
  if (length < 2) return 0;
  if (length == 2) return 1;
  if (length == 3) return 2;
  vector<int> ret = {0, 1, 2, 3};  // 绳子的长度
  for (int i = 4; i <= length; ++i) {
    int tmp = 0;
    for (int j = 1; j <= i / 2; ++j) {
      tmp = max(tmp, ret[j] * ret[i - j]);
    }
    ret.push_back(tmp);
  }
  return ret[length];
}

// 当length >= 5时，尽可能剪长度为3的绳子
// 当length = 4时，剪长度为2的绳子
int cuttingRopeGreedy(const int &length) {
  if (length < 2) return 0;
  if (length == 2) return 1;
  if (length == 3) return 2;
  int times_of_3 = length / 3;
  int mod = length % 3;
  if (mod == 1) {
    times_of_3 -= 1;
  }
  int times_of_2 = (length - times_of_3 * 3) / 2;
  return pow(3, times_of_3) * pow(2, times_of_2);
}

int main() {
  cout << "solution length result expected" << endl;
  cout << "Dp 7 " << cuttingRopeDp(7) << " 12" << endl;
  cout << "Greedy 7 " << cuttingRopeGreedy(7) << " 12" << endl;

  cout << "Dp 9 " << cuttingRopeDp(9) << " 27" << endl;
  cout << "Greedy 9 " << cuttingRopeGreedy(9) << " 27" << endl;

  cout << "Dp 10 " << cuttingRopeDp(10) << " 36" << endl;
  cout << "Greedy 10 " << cuttingRopeGreedy(10) << " 36" << endl;
  return 0;
}
